<template>
	<view class="mine-bg">
		<view class="login-bg-top">
			<image src="/static/img/minePages/topBg.png" mode="widthFix" class="bg-img" />
		</view>
		<!-- 顶部用户信息区 -->
		<view class="user-info">
			<view class="user-texts">
				<view class="user-name-row">
					<text class="user-name">{{ userInfo.nickname }}</text>
					<image :src="userCertIcon" mode="widthFix" class="user-cert" />
				</view>
				<text class="user-unit">{{ userInfo.department }}</text>
			</view>
			<image class="user-avatar" :src="userInfo.avatar" mode="aspectFill" />
		</view>

		<!-- 菜单卡片区 -->
		<view class="menu-card">
			<image src="/static/img/minePages/menu-card-top.png" mode="widthFix" class="menu-card-bg-top" />
			<image src="/static/img/minePages/menu-card-bottom.png" mode="widthFix" class="menu-card-bg-bottom" />
			<view class="menu-item" v-for="(module, index) in availableModules" :key="module.id" @click="mygo(module.path)">
				<view class="menu-left">
					<image class="menu-icon" :src="module.icon" mode="widthFix" />
					<text class="menu-title">{{ module.name }}</text>
				</view>
				<image class="menu-arrow" src="/static/img/minePages/mine-arrow.png" mode="widthFix" />
			</view>
		</view>

		<!-- 底部公司信息区 -->
		<image src="/static/img/minePages/company-info.png" mode="widthFix" class="company-info" />
	</view>
</template>

<script setup>
import { mygo } from '@/utils/useNavigator';
import { useGlobalStore } from '@/store/app';
import { storeToRefs } from 'pinia';
import { computed } from 'vue';

// 获取用户信息存储
const globalStore = useGlobalStore();
const { userInfo } = storeToRefs(globalStore);

// 前端固定的模块配置
const ALL_MODULES = [
	{ id: 'account', name: '账号管理', icon: '/static/img/minePages/account-icon.png', path: '/pages/minePages/account' },
	{ id: 'blacklist', name: '黑白名单管理', icon: '/static/img/minePages/blacklist-icon.png', path: '/pages/minePages/blacklist' },
	{ id: 'addNew', name: '添加新设备', icon: '/static/img/minePages/addNew-icon.png', path: '/pages/minePages/addNew' },
	{ id: 'public', name: '公共区域管理', icon: '/static/img/minePages/public-icon.png', path: '/pages/minePages/public' },
	{ id: 'dev1ce', name: '重点电器管理', icon: '/static/img/minePages/dev1ce-icon.png', path: '/pages/minePages/dev1ce' },
	{ id: 'screen', name: '大屏展示', icon: '/static/img/minePages/screen-icon.png', path: '/pages/minePages/screen' },
	{ id: 'report', name: '报表生成', icon: '/static/img/minePages/report-icon.png', path: '/pages/minePages/report' },
	{ id: 'system', name: '系统设置', icon: '/static/img/minePages/system-icon.png', path: '/pages/minePages/system' }
];

// 根据用户权限过滤可用模块
const availableModules = computed(() => {
	const userModules = userInfo.value.modules || [];

	return ALL_MODULES.filter((module) => {
		// 系统设置始终显示
		if (module.id === 'system') {
			return true;
		}
		// 其他模块根据用户权限过滤
		return userModules.includes(module.id);
	});
});

// 根据用户角色获取认证图标
const userCertIcon = computed(() => {
	const role = userInfo.value.role;
	switch (role) {
		case 'onsite':
			return '/static/img/minePages/user-cert.png'; // 现场角色图标（暂时使用相同图标）
		case 'offsite':
			return '/static/img/minePages/user-cer.png'; // 非现场角色图标
		default:
			return '/static/img/minePages/user-cer.png'; // 默认图标
	}
});
</script>

<style scoped lang="scss">
.login-bg-top {
	position: fixed;
	top: 0;
	left: 0;
	width: 100vw;
	height: 416rpx;
	z-index: 0;
	pointer-events: none;
}
.bg-img {
	width: 100vw;
	height: 200rpx;
	object-fit: cover;
	display: block;
}
.mine-bg {
	min-height: calc(100vh - 90rpx);
	background: #172869;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: 160rpx;
	box-sizing: border-box;
}

.user-info {
	width: 90vw;
	max-width: 700rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 40rpx;
}
.user-texts {
	display: flex;
	flex-direction: column;
}
.user-name-row {
	display: flex;
	align-items: center;
	margin-bottom: 8rpx;
}
.user-name {
	font-size: 40rpx;
	color: #fff;
	font-weight: bold;
	margin-right: 12rpx;
}
.user-cert {
	width: 44rpx;
	height: 44rpx;
}
.user-unit {
	font-size: 24rpx;
	color: #b0b8d0;
}
.user-avatar {
	width: 120rpx;
	height: 120rpx;
	border-radius: 50%;
	overflow: hidden;
}

.menu-card {
	width: 686rpx;
	background: linear-gradient(180deg, #0A2B76 0%, #07163F 100%);
	padding: 0 30rpx;
	box-sizing: border-box;
	margin-top: 80rpx;
	border-left: 4rpx solid #2b95e5;
	border-right: 4rpx solid #2b95e5;
	position: relative;
}
.menu-card-bg-top {
	position: absolute;
	top: -30rpx;
	left: -3.5rpx;
	width: 685.5rpx;
	z-index: 0;
	pointer-events: none;
}
.menu-card-bg-bottom {
	position: absolute;
	bottom: -30rpx;
	left: -3.5rpx;
	width: 685.5rpx;
	z-index: 0;
	pointer-events: none;
}
.menu-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	height: 120rpx;
}
.menu-left {
	display: flex;
	align-items: center;
}
.menu-icon {
	width: 48rpx;
	height: 48rpx;
	margin-right: 24rpx;
}
.menu-title {
	font-size: 28rpx;
	color: rgba(255, 255, 255, 0.8);
}
.menu-arrow {
	height: 24rpx;
	width: 14rpx;
}

.company-info {
	position: fixed;
	bottom: 170rpx;
	left: 0;
	width: 100vw;
	z-index: -1;
}
</style>
